<?php
class MemberinfoAction extends BaseAction {
	public function info() {
		$_SESSION['userid']=$_GET['id'];
		$this->display();
	}
	
	public function base() {
		$User = M('Uinfo'); 
		$Opt = M('Option');
		$userinfo = $User->getByUserid($_SESSION['userid']);
		// 防止页面乱码  
		header ( 'Content-type:text/html;charset=utf-8' );
		
		$opt_condition['opt_flag'] = "year";
		$yearlist = $Opt->order('opt_id')->where($opt_condition)->select();
		$opt_condition['opt_flag'] = "month";
		$monthlist = $Opt->order('opt_id')->where($opt_condition)->select();
		$opt_condition['opt_flag'] = "day";
		$daylist = $Opt->order('opt_id')->where($opt_condition)->select();
		$opt_condition['opt_flag'] = "height";
		$heightlist = $Opt->order('opt_id')->where($opt_condition)->select();
		$opt_condition['opt_flag'] = "weight";
		$weightlist = $Opt->order('opt_id')->where($opt_condition)->select();
		$opt_condition['opt_flag'] = "waistline";
		$waistlinelist = $Opt->order('opt_id')->where($opt_condition)->select();
		//$opt_condition['opt_flag'] = "province";
		//$provincelist = $Opt->order('opt_id')->where($opt_condition)->select();
		
		$this->assign("yearlist",$yearlist);
		$this->assign("monthlist",$monthlist);
		$this->assign("daylist",$daylist);
		$this->assign("heightlist",$heightlist);
		$this->assign("weightlist",$weightlist);
		$this->assign("waistlinelist",$waistlinelist);
		
		//$this->assign("provincelist",$provincelist);
		$this->assign("user",$userinfo);
		$this->display();
	}
	
	public function basemodify() {
		$User = M('Uinfo');
		$info = $User->getByUserid($_SESSION['userid']);
		// 防止页面乱码  
		header ( 'Content-type:text/html;charset=utf-8' );
		
		if($info['mobilePh']!=$_POST['user_mobile']) $data['mobilePh'] = $_POST['user_mobile'];
		if($info['email']!=$_POST['user_email']) $data['email'] = $_POST['user_email'];
		if($info['truename']!=$_POST['user_truename']) $data['truename'] = $_POST['user_truename'];
		if($info['gender']!=$_POST['user_sex']) $data['gender'] = $_POST['user_sex'];
		$birthday = $_POST['user_birthday_y'].'-'.$_POST['user_birthday_m'].'-'.$_POST['user_birthday_d'];
		if($info['birthday']!=$birthday) $data['birthday'] = $birthday;
		if($info['height']!=$_POST['user_height']) $data['height'] = $_POST['user_height'];
		if($info['weight']!=$_POST['user_weight']) $data['weight'] = $_POST['user_weight'];
		if($info['waistline']!=$_POST['user_waistline']) $data['waistline'] = $_POST['user_waistline'];
		//if($info['user_province']!=$_POST['user_province']) $data['user_province'] = $_POST['user_province'];
		//if($info['user_city']!=$_POST['user_city']) $data['user_city'] = $_POST['user_city'];
		//if($info['user_edu']!=$_POST['user_edu']) $data['user_edu'] = $_POST['user_edu'];
		if ($info['userType'] != $_POST['user_type']) $data['userType'] = $_POST['user_type'];
		if ($info['veriEmail'] != $_POST['veri_email']) $data['veriEmail'] = $_POST['veri_email'];
		if ($info['veriMobile'] != $_POST['veri_mobile']) $data['veriMobile'] = $_POST['veri_mobile'];
		//if ($info ['sources'] != $_POST ['user_source']) $data ['sources'] = $_POST ['user_source'];
		if ($info['state'] != $_POST['user_state']) $data ['state'] = $_POST['user_state'];
		//if ($info ['user_intro']!=$_POST['user_intro']) $data['user_intro'] = $_POST['user_intro'];
		if($info['remark']!=$_POST['user_remark']) $data['remark'] = $_POST['user_remark'];
		
		if($data) {
			$condition['userId'] = $info['userId'];
			$result = $User->where($condition)->save($data);
			if($result)
				echo "<script language=\"javascript\">alert('修改成功！');window.location.href='base';</script>";
			else 
				$this->error ( '数据写入错误！请重试...' );
		}
		else echo "<script language=\"javascript\">alert('资料没有更新！');window.location.href='base';</script>";
		//$this->redirect('base');
	}
	
	public function detail() {
		$Detail = M('Detail'); 
		$User = M('User');
		$Opt = M('Option');
		$det_condition['user_id'] = $_SESSION['userid'];
		$info = $Detail->where($det_condition)->find();
		$u = $User->where($det_condition)->find();
		//防止页面乱码  
		header ( 'Content-type:text/html;charset=utf-8' );
		
		$opt_condition['opt_flag'] = "nation";
		$nationlist = $Opt->order('opt_id')->where($opt_condition)->select();
		$opt_condition['opt_flag'] = "province";
		$provincelist = $Opt->order('opt_id')->where($opt_condition)->select();
		$opt_condition['opt_flag'] = "language";
		$languagelist = $Opt->order('opt_id')->where($opt_condition)->select();
		if($u['user_sex']=='男士') $opt_condition['opt_flag'] = "appearance_m";
		else $opt_condition['opt_flag'] = "appearance_f";
		$appearancelist = $Opt->order('opt_id')->where($opt_condition)->select();
		$opt_condition['opt_flag'] = "charm";
		$charmlist = $Opt->order('opt_id')->where($opt_condition)->select();
		
		$this->assign("nationlist",$nationlist);
		$this->assign("provincelist",$provincelist);
		$this->assign("languagelist",$languagelist);
		$this->assign("appearancelist",$appearancelist);
		$this->assign("charmlist",$charmlist);
		$this->assign("detail",$info);
		$this->display();
	}
	
	public function detailmodify() {
		$Detail = M('Detail');
		$condition['user_id'] = $_SESSION['userid'];
		$info = $Detail->where($condition)->find();
		//防止页面乱码  
		header ( 'Content-type:text/html;charset=utf-8' );
		
		if($info['id_number']!=$_POST['id_number']) $data['id_number'] = $_POST['id_number'];
		if($info['qq']!=$_POST['qq']) $data['qq'] = $_POST['qq'];
		if($info['real_name']!=$_POST['real_name']) $data['real_name'] = $_POST['real_name'];
		if($info['veri_name']!=$_POST['veri_name']) $data['veri_name'] = $_POST['veri_name'];
		if($info['nation']!=$_POST['nation']) $data['nation'] = $_POST['nation'];
		if($info['blood_type']!=$_POST['blood_type']) $data['blood_type'] = $_POST['blood_type'];
		if($info['hometown_province']!=$_POST['home_province']) $data['hometown_province'] = $_POST['home_province'];
		if($info['hometown_city']!=$_POST['home_city']) $data['hometown_city'] = $_POST['home_city'];
		if($info['religious_belief']!=$_POST['religious_belief']) $data['religious_belief'] = $_POST['religious_belief'];
		if($info['parents_info']!=$_POST['parents_info']) $data['parents_info'] = $_POST['parents_info'];
		if($info['cousins_info']!=$_POST['cousins_info']) $data['cousins_info'] = $_POST['cousins_info'];
		if($info['family_info']!=$_POST['family_info']) $data['family_info'] = $_POST['family_info'];
		$language = $_POST['language'];$language = implode("、",$language); //合并数组成字符串
		if($info['language']!=$language) $data['language'] = $language;
		if($info['personality']!=$_POST['personality']) $data['personality'] = $_POST['personality'];
		if($info['appearance']!=$_POST['appearance']) $data['appearance'] = $_POST['appearance'];
		if($info['face_size']!=$_POST['face_size']) $data['face_size'] = $_POST['face_size'];
		if($info['body_size']!=$_POST['body_size']) $data['body_size'] = $_POST['body_size'];
		if($info['hairstyle']!=$_POST['hairstyle']) $data['hairstyle'] = $_POST['hairstyle'];
		if($info['hair_color']!=$_POST['hair_color']) $data['hair_color'] = $_POST['hair_color'];
		$charm = $_POST['charm'];$charm = implode("、",$charm); 
		if($info['charm']!=$charm) $data['charm'] = $charm;
		
		if($data) {
			$result = $Detail->where($condition)->save($data);
			if($result)
				echo "<script language=\"javascript\">alert('修改成功！');window.location.href='detail';</script>";
			else 
				$this->error ( '数据写入错误！请重试...' );
		}
		else echo "<script language=\"javascript\">alert('资料没有更新！');window.location.href='detail';</script>";
	}
	
	public function interest() {
		$Interest = M('Interest');
		$Opt = M('Option');
		$int_condition['user_id'] = $_SESSION['userid'];
		$info = $Interest->where($int_condition)->find();
		//防止页面乱码  
		header ( 'Content-type:text/html;charset=utf-8' );
		
		$opt_condition['opt_flag'] = "hobby";
		$hobbylist = $Opt->order('opt_id')->where($opt_condition)->select();
		$opt_condition['opt_flag'] = "sports";
		$sportslist = $Opt->order('opt_id')->where($opt_condition)->select();
		$opt_condition['opt_flag'] = "music";
		$musiclist = $Opt->order('opt_id')->where($opt_condition)->select();
		$opt_condition['opt_flag'] = "food";
		$foodlist = $Opt->order('opt_id')->where($opt_condition)->select();
		$opt_condition['opt_flag'] = "film";
		$filmlist = $Opt->order('opt_id')->where($opt_condition)->select();
		$opt_condition['opt_flag'] = "travel";
		$travellist = $Opt->order('opt_id')->where($opt_condition)->select();
		$opt_condition['opt_flag'] = "pet";
		$petlist = $Opt->order('opt_id')->where($opt_condition)->select();
		
		$this->assign("sportslist",$sportslist);
		$this->assign("hobbylist",$hobbylist);
		$this->assign("musiclist",$musiclist);
		$this->assign("foodlist",$foodlist);
		$this->assign("filmlist",$filmlist);
		$this->assign("travellist",$travellist);
		$this->assign("petlist",$petlist);
		$this->assign("interest",$info);
		$this->display();
	}
	
	public function interestmodify() {
		$Interest = M('Interest');
		$condition['user_id'] = $_SESSION['userid'];
		$info = $Interest->where($condition)->find();
		//防止页面乱码  
		header ( 'Content-type:text/html;charset=utf-8' );
		
		$hobby = $_POST['hobby'];$hobby = implode("、",$hobby); //合并数组成字符串
		if($info['hobby']!=$hobby) $data['hobby'] = $hobby;
		$sports = $_POST['sports'];$sports = implode("、",$sports); 
		if($info['sports']!=$sports) $data['sports'] = $sports;
		$music = $_POST['music'];$music = implode("、",$music); 
		if($info['music']!=$music) $data['music'] = $music;
		$food = $_POST['food'];$food = implode("、",$food); 
		if($info['food']!=$food) $data['food'] = $food;
		$film = $_POST['film'];$film = implode("、",$film); 
		if($info['films']!=$film) $data['films'] = $film;
		$travel = $_POST['travel'];$travel = implode("、",$travel); 
		if($info['travel']!=$travel) $data['travel'] = $travel;
		$pet = $_POST['pet'];$pet = implode("、",$pet); 
		if($info['pets']!=$pet) $data['pets'] = $pet;
		if($info['interest_info']!=$_POST['interest_info']) $data['interest_info'] = $_POST['interest_info'];
		
		if($data) {
			$result = $Interest->where($condition)->save($data);
			if($result)
				echo "<script language=\"javascript\">alert('修改成功！');window.location.href='interest';</script>";
			else 
				$this->error ( '数据写入错误！请重试...' );
		}
		else echo "<script language=\"javascript\">alert('资料没有更新！');window.location.href='interest';</script>";
	}
	
	public function work() {
		$Work = M('Work');
		$Opt = M('Option');
		$work_condition['user_id'] = $_SESSION['userid'];
		$info = $Work->where($work_condition)->find();
		//防止页面乱码  
		header ( 'Content-type:text/html;charset=utf-8' );
		
		$opt_condition['opt_flag'] = "major";
		$majorlist = $Opt->order('opt_id')->where($opt_condition)->select();
		$opt_condition['opt_flag'] = "job";
		$joblist = $Opt->order('opt_id')->where($opt_condition)->select();
		$opt_condition['opt_flag'] = "entertainment";
		$enterlist = $Opt->order('opt_id')->where($opt_condition)->select();
		
		$this->assign("majorlist",$majorlist);
		$this->assign("joblist",$joblist);
		$this->assign("enterlist",$enterlist);
		$this->assign("work",$info);
		$this->display();
	}
	
	public function workmodify() {
		$Work = M('Work');
		$condition['user_id'] = $_SESSION['userid'];
		$info = $Work->where($condition)->find();
		//防止页面乱码  
		header ( 'Content-type:text/html;charset=utf-8' );
		
		if($info['grad_school']!=$_POST['grad_school']) $data['grad_school'] = $_POST['grad_school'];
		if($info['major']!=$_POST['major']) $data['major'] = $_POST['major'];
		if($info['job']!=$_POST['job']) $data['job'] = $_POST['job'];
		if($info['company']!=$_POST['company']) $data['company'] = $_POST['company'];
		if($info['job_des']!=$_POST['job_des']) $data['job_des'] = $_POST['job_des'];
		if($info['smoking']!=$_POST['smoking']) $data['smoking'] = $_POST['smoking'];
		if($info['drinking']!=$_POST['drinking']) $data['drinking'] = $_POST['drinking'];
		if($info['housework']!=$_POST['housework']) $data['housework'] = $_POST['housework'];
		if($info['cooking']!=$_POST['cooking']) $data['cooking'] = $_POST['cooking'];
		if($info['exercise']!=$_POST['exercise']) $data['exercise'] = $_POST['exercise'];
		if($info['schedule']!=$_POST['schedule']) $data['schedule'] = $_POST['schedule'];
		if($info['consuming']!=$_POST['consuming']) $data['consuming'] = $_POST['consuming'];
		$entertainment = $_POST['entertainment'];$entertainment = implode("、",$entertainment); 
		if($info['entertainment']!=$entertainment) $data['entertainment'] = $entertainment;
		
		if($data) {
			$result = $Work->where($condition)->save($data);
			if($result)
				echo "<script language=\"javascript\">alert('修改成功！');window.location.href='work';</script>";
			else 
				$this->error ( '数据写入错误！请重试...' );
		}
		else echo "<script language=\"javascript\">alert('资料没有更新！');window.location.href='work';</script>";
	}
	
	public function mate() {
		$Mate = M('Mate');
		$Opt = M('Option');
		$work_condition['user_id'] = $_SESSION['userid'];
		$info = $Mate->where($work_condition)->find();
		
		$opt_condition['opt_flag'] = "age";
		$agelist = $Opt->order('opt_id')->where($opt_condition)->select();
		$opt_condition['opt_flag'] = "height";
		$heightlist = $Opt->order('opt_id')->where($opt_condition)->select();
		$opt_condition['opt_flag'] = "province";
		$provincelist = $Opt->order('opt_id')->where($opt_condition)->select();
		$opt_condition['opt_flag'] = "nation";
		$nationlist = $Opt->order('opt_id')->where($opt_condition)->select();
		$opt_condition['opt_flag'] = "job";
		$joblist = $Opt->order('opt_id')->where($opt_condition)->select();
		
		$this->assign("agelist",$agelist);
		$this->assign("heightlist",$heightlist);
		$this->assign("provincelist",$provincelist);
		$this->assign("nationlist",$nationlist);
		$this->assign("joblist",$joblist);
		$this->assign("mate",$info);
		$this->display();
	}

	public function matemodify() {
		$Mate = M('Mate');
		$condition['user_id'] = $_SESSION['userid'];
		$info = $Mate->where($condition)->find();
		//防止页面乱码  
		header ( 'Content-type:text/html;charset=utf-8' );
		
		if($info['nation']!=$_POST['nation']) $data['nation'] = $_POST['nation'];
		if($info['age_min']!=$_POST['age_min']) $data['age_min'] = $_POST['age_min'];
		if($info['age_max']!=$_POST['age_max']) $data['age_max'] = $_POST['age_max'];
		if($info['height_min']!=$_POST['height_min']) $data['height_min'] = $_POST['height_min'];
		if($info['height_max']!=$_POST['height_max']) $data['height_max'] = $_POST['height_max'];
		if($info['local_province']!=$_POST['local_province']) $data['local_province'] = $_POST['local_province'];
		if($info['local_city']!=$_POST['local_city']) $data['local_city'] = $_POST['local_city'];
		if($info['home_province']!=$_POST['home_province']) $data['home_province'] = $_POST['home_province'];
		if($info['home_city']!=$_POST['home_city']) $data['home_city'] = $_POST['home_city'];
		if($info['education']!=$_POST['education']) $data['education'] = $_POST['education'];
		if($info['job']!=$_POST['job']) $data['job'] = $_POST['job'];
		if($info['income']!=$_POST['income']) $data['income'] = $_POST['income'];
		if($info['marriage']!=$_POST['marriage']) $data['marriage'] = $_POST['marriage'];
		if($info['housing']!=$_POST['housing']) $data['housing'] = $_POST['housing'];
		if($info['vehicle']!=$_POST['vehicle']) $data['vehicle'] = $_POST['vehicle'];
		if($info['living']!=$_POST['living']) $data['living'] = $_POST['living'];
		if($info['kids']!=$_POST['kids']) $data['kids'] = $_POST['kids'];
		if($info['body_size']!=$_POST['body_size']) $data['body_size'] = $_POST['body_size'];
		if($info['want_kids']!=$_POST['want_kids']) $data['want_kids'] = $_POST['want_kids'];
		if($info['smoking']!=$_POST['smoking']) $data['smoking'] = $_POST['smoking'];
		if($info['drinking']!=$_POST['drinking']) $data['drinking'] = $_POST['drinking'];
		if($info['photo']!=$_POST['photo']) $data['photo'] = $_POST['photo'];
		if($info['identify']!=$_POST['identify']) $data['identify'] = $_POST['identify'];
		
		if($data) {
			$result = $Mate->where($condition)->save($data);
			if($result)
				echo "<script language=\"javascript\">alert('修改成功！');window.location.href='mate';</script>";
			else 
				$this->error ( '数据写入错误！请重试...' );
		}
		else echo "<script language=\"javascript\">alert('资料没有更新！');window.location.href='mate';</script>";
	}
	
	public function photo() {
		$Photo = M('Photo');
		$photo_condition['user_id'] = $_SESSION['userid'];
		$photo_condition['sort'] = '1';
		$photo_condition['state'] = '1';
		$photolist = $Photo->where($photo_condition)->select();
		$count = count($photolist);
		
		// 导入分页类
   	 	import("ORG.Util.Page");
    	// 实例化分页类
    	$p = new Page($count, 14);
    	$p->setConfig('prev',"<");  
		$p->setConfig('first','<<');
		$p->setConfig('last','>>');
		$p->setConfig('next','>');
		
		// 分页显示输出
    	$page = $p->show();
		$photolist = $Photo->order('photo_id DESC')->limit($p->firstRow.','.$p->listRows)->where($photo_condition)->select(); 
		$photo_condition['head_pic'] = '1';
		$headPic =  $Photo->where($photo_condition)->find();
		
		//防止页面乱码  
		header ( 'Content-type:text/html;charset=utf-8' );
		$this->assign('page', $page);
		$this->assign("photolist",$photolist);
		$this->assign("headPic",$headPic);
		$this->display();
	}
	
	public function photoupload() {
		//防止页面乱码  
		header ( 'Content-type:text/html;charset=utf-8' );
		$Photo = M('Photo');
		
		if(is_uploaded_file($_FILES['uploadPhoto']['tmp_name'])){
			$upfile=$_FILES["uploadPhoto"];
			$name=$upfile["name"]; //重命名照片
			$tmp=substr($name, -4,4);
			$name=date('YmdHis').$tmp;
			
			$type=$upfile["type"];
			$size=$upfile["size"];
			$tmp_name=$upfile["tmp_name"];
			$error=$upfile["error"];
 		}
		if($error=='0') move_uploaded_file($tmp_name,'Public/Uploads/photos/'.$name);
	
		$data['user_id'] = $_SESSION['userid'];
		$data['sort'] = '1';
		$data['upload_time'] = "20".date ('y-m-d H:i:s',time()); 
		$data['state'] = '1';
		$data['verify'] = '1';
		if($_POST['headpic']==1) {
			$data['head_pic'] = '1';
			$temp['head_pic'] = '0';
			$Photo->where($data)->save($temp);
		} 
		$data['photo_url'] = $name;
		$result = $Photo->add($data);
		if($result)
			echo "<script language=\"javascript\">alert('上传成功！');window.location.href='photo';</script>";
		else 
			$this->error ( '数据写入错误！请重试...' );
	}
	
	public function headpicmodify() {
		$Photo = M('Photo');
		$condition['user_id'] = $_SESSION['userid'];
		$condition['sort'] = '1';
		$condition['state'] = '1';
		$condition['head_pic'] = '1';
		$data['head_pic'] ='0';
		$Photo->where($condition)->save($data);
		
		$ph['photo_id'] = $_GET['photoid'];
		$data['head_pic'] ='1';
		$result = $Photo->where($ph)->save($data);
		if($result)
			$this->redirect('photo');
		else 
			$this->error ( '数据写入错误！请重试...' );
	}
	
	public function photodelete() {
		//防止页面乱码  
		header ( 'Content-type:text/html;charset=utf-8' );
		$Photo = M('Photo');
		$condition['photo_id'] = $_GET['photoid'];
		$data = $Photo->where($condition)->find();
		$result = $Photo->where($condition)->delete();
		if($result) {
			if(file_exists("Public/Uploads/photos/".$data['photo_url'])) {
				unlink("Public/Uploads/photos/".$data['photo_url']);
			}
			echo "<script language=\"javascript\">alert('删除成功！');window.location.href='../../../MemberInfo/photo';</script>";
		}
		else 
			$this->error ( '数据写入错误！请重试...' );
	}
}